package cn.edu.nsmc.modules.sys.controller;

import cn.edu.nsmc.common.utils.R;
import cn.edu.nsmc.modules.sys.entity.SysUserEntity;
import cn.edu.nsmc.modules.sys.entity.SysWorksheetRecord;

import cn.edu.nsmc.modules.sys.service.SysUserTokenService;
import cn.edu.nsmc.modules.sys.service.impl.SysRepairmanServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/sys/repairman")
public class SysRepairmanController extends AbstractController{
    @Autowired
    private SysRepairmanServiceImpl sysRepairmanService;

    //多条件查询维修人员信息
    @PostMapping("getList")
    public R getList(@RequestBody SysUserEntity sysUserEntity, Integer page, Integer size) {
        return sysRepairmanService.getList(sysUserEntity, (page - 1) * size, size);
    }

    @GetMapping("getSelectList")
    public R getSelectList(String name) {
        return sysRepairmanService.getSelectList(name);
    }

    //批量导入导出
    @GetMapping("getExcelTemplate")
    public void getExcelTemplate(HttpServletResponse response) throws IOException {
        sysRepairmanService.getExcelTemplate(response);
    }

    @PostMapping("importRepairman")
    public R importRepairman(@RequestBody MultipartFile file, Long userId) {
        userId =getUserId();
        return sysRepairmanService.importRepairman(file, userId);
    }

    @PostMapping("exportRepairman")
    public void exportRepairman(@RequestBody SysUserEntity sysUserEntity, HttpServletResponse response) throws IOException {
        sysRepairmanService.exportRepairman(sysUserEntity, response);
    }

    //维修数据统计
    @PostMapping("queryStatistics")
    public R queryStatistics(@RequestBody SysUserEntity sysUserEntity) {
        return sysRepairmanService.queryStatistics(sysUserEntity);
    }

    @PostMapping("exportStatistics")
    public void exportStatistics(@RequestBody SysUserEntity sysUserEntity, HttpServletResponse response) {
        sysRepairmanService.exportStatistics(sysUserEntity, response);
    }
}
